package com.oristartech.ori.common.generater.test;

import java.io.File;

public class UpdateFileName {

    private static final String[] DIRECTORYS =
        new String[] {"E:\\Git\\Remote\\ctm\\ctm-service\\src\\main\\resources\\mapping",
            "E:\\Git\\Remote\\csm\\csm-service\\src\\main\\resources\\mapping",
            "E:\\Git\\Remote\\csm\\csm-share-service\\src\\main\\resources\\mapping"};

    public static void main(String[] args) {
        for (String directory : DIRECTORYS) {
            File file = new File(directory);
            renameMapperXmlName(file);
        }
    }

    public static void renameMapperXmlName(File file) {
        if (file == null || !file.isDirectory()) {
            return;
        }
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isDirectory()) {
                renameMapperXmlName(f);
            }
            if (!f.isFile()) {
                continue;
            }
            String fileName = f.getName();
            if (!fileName.endsWith("Mapper.xml") || fileName.matches("^[A-Z].*$")) {
                continue;
            }
            System.out.println(fileName);
            String newFileName = (new StringBuilder()).append(Character.toUpperCase(fileName.charAt(0)))
                .append(fileName.substring(1)).toString();
            File newFile = new File(f.getParent() + File.separator + newFileName);
            f.renameTo(newFile);
        }
    }
}
